#!/bin/bash
DB_HOST1="127.0.0.1"
DB_PORT1="5236"
SYSDBA_PWD="Dameng123"
DM_BIN=$(cd "$(dirname "$0")/../dm8/bin";pwd)
TEST_NODE="1"  #choose 1 or 0
TEST_FLAG="1"  #choose 1 or 0
ACID_FLAG="0"
CKPT_FLAG="1"
PREHEAT_FALG="1"
#For Benchmarksql
RUNMINS="3"
#warehouse,partition table only support:100,200,300,400,500,600,800,1000,2000
WAREHOUSES="100"
TERMINALS="10"
SCRIPTS_DIR=`pwd`

sleep 1
$(cd "$(dirname "$0")/../init_dm8/";pwd)/DmService start
sleep 1

for ((cda=0; cda<120; cda++))
do
	dmserver_alive=`lsof -i:${DB_PORT1}|awk 'NR==2{print $2}'`
	if [ -z "${dmserver_alive}" ]
	then
		echo "check_dmserver_alive $[5*$cda] sec"
		sleep 5
	else
		echo "dmserver started"
		break
	fi
done

#export var
filename=`echo $(basename $0)|sed 's/.sh//g'`
export filename SYSDBA_PWD
export DB_HOST1 DB_PORT1 DB_HOST2 DB_PORT2 DB_HOST3 DB_PORT3 DB_HOST4 DB_PORT4
export DB_HOST5 DB_PORT5 DB_HOST6 DB_PORT6 DB_HOST7 DB_PORT7 DB_HOST8 DB_PORT8
export DM_BIN TABLE_TYPE TEST_NODE ACID_FLAG CKPT_FLAG PREHEAT_FALG TEST_FLAG
export RUNMINS WAREHOUSES LOADWORKERS TERMINALS

#add +x
chmod +x ${SCRIPTS_DIR}/01_tpcc/*.sh
chmod +x ${SCRIPTS_DIR}/01_tpcc/tpcc/benchmarksql5/run/*.sh
chmod +x ${SCRIPTS_DIR}/01_tpcc/tpcc/benchmarksql5/run/misc/*
chmod +x ${SCRIPTS_DIR}/01_tpcc/tpcc/benchmarksql5_fk/run/*.sh
chmod +x ${SCRIPTS_DIR}/01_tpcc/tpcc/benchmarksql5_fk/run/misc/*
#For bms5
if [ $TEST_NODE = "1" ]; then
  sh ${SCRIPTS_DIR}/01_tpcc/01_test.sh
elif [ $TEST_NODE != "1" ]; then
  sh ${SCRIPTS_DIR}/01_tpcc/02_test_fk.sh
fi
